package org.springframework.example.aop;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.example.aop.advice.MyAroundAdvice;
import org.springframework.example.aop.advice.MyBeforeAdvice;
import org.springframework.example.aop.service.AccountService;

import java.lang.reflect.Method;

public class Test {

	public static void main(String[] args) {

		AccountService service = new AccountService();
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(AccountService.class);
		enhancer.setCallback(new MethodInterceptor(){
			@Override
			public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
				System.out.println("before...");
				Object result = methodProxy.invoke(service, objects);
				System.out.println("after...");
				return result;
			}
		});
		AccountService accountService = (AccountService) enhancer.create();
		accountService.test();


	}
}
